import QtQuick 2.1
import QtQuick.Layouts 1.0
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.0
import org.qtproject.qtquick 1.0
import "qrc:/js/resources/Constants.js" as Constant

import "page"
import "delegate"


ApplicationWindow {

    id: id_mainWindow

    width: Constant.width * m_ratio
    height: Constant.height * m_ratio

    title: "Zingme Message"

//======================================================================================
    property real m_ratio : ApplicationInfo.ratio;

    property Component waitPage : WaitPage{

    }

//======================================================================================
    function startOpeningFriendListPage() {
        id_pageView.pop();
        id_pageView.push(Qt.resolvedUrl("page/MainPage.qml"));
        console.log("MainWindow.qml :============= startOpeningFriendListPage");
    }

    function logoutAccountSuccess() {
        id_pageView.pop();
        id_pageView.push(Qt.resolvedUrl("page/LoginPage.qml"));
        console.log("MainWindow.qml ================== Loguted  ");
    }

    function onRequireLogin(){
        id_pageView.pop();
        id_pageView.push(Qt.resolvedUrl("page/LoginPage.qml"));
        console.log("MainWindow.qml :============= startOpening LoginPage");
    }

//======================================================================================
    StackView {
        id: id_pageView
        anchors.fill: parent
        focus: true
        initialItem: waitPage

        delegate: StackViewDelegate {
            pushTransition: StackViewTransition {
                function transitionFinished(properties)
                {
                    properties.exitItem.opacity = 1
                }
                PropertyAnimation {
                    target: enterItem
                    property: "x"
                    from: target.width
                    to: 0
                    duration: 500
                    easing.type: Easing.OutSine
                }
                PropertyAnimation {
                    target: exitItem
                    property: "x"
                    from: 0
                    to: -target.width
                    duration: 500
                    easing.type: Easing.OutSine
                }
            }
            popTransition: StackViewTransition {
                function transitionFinished(properties)
                {
                    properties.exitItem.opacity = 1
                }
                PropertyAnimation {
                    target: enterItem
                    property: "x"
                    from: -target.width
                    to: 0
                    duration: 500
                    easing.type: Easing.OutSine
                }
                PropertyAnimation {
                    target: exitItem
                    property: "x"
                    from: 0
                    to: target.width
                    duration: 500
                    easing.type: Easing.OutSine

                }
            }
            property Component replaceTransition: pushTransition
        }
    }
//======================================================================================
    Component.onCompleted:  {
        ApplicationInfo.requireLogin.connect(onRequireLogin);
        ApplicationInfo.startOpeningFriendListPage.connect(startOpeningFriendListPage);
        ApplicationInfo.logoutAccountSuccess.connect(logoutAccountSuccess);

        ApplicationInfo.initData();

    }

}
